package cn.hl.hm.util.alipayJs;

import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStream;  
import java.io.InputStreamReader;  

import org.apache.http.HttpEntity;  
import org.apache.http.HttpResponse;  
import org.apache.http.client.ClientProtocolException;  
import org.apache.http.client.HttpClient;  
import org.apache.http.client.methods.HttpGet;  
import org.apache.http.impl.client.DefaultHttpClient;  

public class TTT {  

    /** 
     * @param args 
     * @throws IOException  
     * @throws ClientProtocolException  
     */  
    public static void main(String[] args) throws ClientProtocolException, IOException {  
        // 创建HttpClient实例     
        HttpClient httpclient = new DefaultHttpClient();  
        // 创建Get方法实例     
//        HttpGet httpgets = new HttpGet("https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx489321bacf87bcef&secret=c5504674e103380340d4d8ace0a912f9&code=0013LZAK0F84Hj2379zK0k8ZAK03LZAR&grant_type=authorization_code"); 
        HttpGet httpgets = new HttpGet("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa9c5dca62dbbe6b5&redirect_uri=http://apitest.hlvan.cn/alipayment/js_api_call.jsp&response_type=code&scope=snsapi_base&state=123");
        HttpResponse response = httpclient.execute(httpgets);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream instreams = entity.getContent();
            String str = convertStreamToString(instreams);
            System.out.println("Do something");
            System.out.println(str);
            // Do not need the rest
            httpgets.abort();    
        }  
    }  
      
    public static String convertStreamToString(InputStream is) {      
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));      
        StringBuilder sb = new StringBuilder();      
       
        String line = null;      
        try {      
            while ((line = reader.readLine()) != null) {  
                sb.append(line + "\n");      
            }      
        } catch (IOException e) {      
            e.printStackTrace();      
        } finally {      
            try {      
                is.close();      
            } catch (IOException e) {
               e.printStackTrace();      
            }      
        }      
        return sb.toString();      
    }  
  
}
